package com.fadadianqi.commons;

import com.yeqiangwei.commons.util.DateTimeUtils;
import com.yeqiangwei.commons.util.ParamUtils;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ParamHelper {

    private static final String ID = "id";
    private static final String NAME = "nm";
    private static final String PASSWORD = "pwd";
    private static final String STORE_HOUSE_ID = "shid";
    private static final String CUSTOMER_ID = "ctid";
    private static final String GOODS_ID = "gid";
    private static final String BILL_ID = "blid";
    private static final String BRAND_ID = "bid";
    private static final String CATEGORY_ID = "cid";
    private static final String BATCH_ID = "bcid";
    private static final String GROUP_ID = "gpid";

    public static String getGroupId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, GROUP_ID, def);
    }

    public static String getName(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, NAME, def);
    }

    public static String getPassword(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, PASSWORD, def);
    }

    public static final String getCategoryId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, CATEGORY_ID, def);
    }

    public static final String getBrandId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, BRAND_ID, def);
    }

    public static final String getId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, ID, def);
    }

    public static final String getGoodsId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, GOODS_ID, def);
    }

    public static final String getCustomerId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, CUSTOMER_ID, def);
    }

    public static final String getStorehouseId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, STORE_HOUSE_ID, def);
    }

    public static String getBillId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, BILL_ID, def);
    }

    public static String getBatchId(HttpServletRequest request, String def) {
        return ParamUtils.getString(request, BATCH_ID, def);
    }

    public static Date getBeginDayTimeByYYYYMMDD(String yyyyMMdd) {
        Date beginDayTime = null;
        SimpleDateFormat sdf = new SimpleDateFormat(DateTimeUtils.FMT_YYYY_MM_DD_HH_MM_SS);
        try {
            beginDayTime = sdf.parse(yyyyMMdd + " 00:00:00");
            if (beginDayTime == null) {
                beginDayTime = new Date();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return beginDayTime;
    }

    public static Date getEndDayTimeByYYYYMMDD(String yyyyMMdd) {
        Date endDayTime = null;
        SimpleDateFormat sdf = new SimpleDateFormat(DateTimeUtils.FMT_YYYY_MM_DD_HH_MM_SS);
        try {
            endDayTime = sdf.parse(yyyyMMdd + " 23:59:59");
            if (endDayTime == null) {
                endDayTime = new Date();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return endDayTime;
    }
}
